import os
import requests
import concurrent.futures
from util.headers import get_header

urls = [
    f"https://push2.eastmoney.com/api/qt/clist/get?np=1&fltt=1&invt=2&fs=m%3A0%2Bt%3A6%2Bf%3A!2%2Cm%3A0%2Bt%3A80%2Bf%3A!2%2Cm%3A1%2Bt%3A2%2Bf%3A!2%2Cm%3A1%2Bt%3A23%2Bf%3A!2%2Cm%3A0%2Bt%3A81%2Bs%3A262144%2Bf%3A!2&fields=f12%2Cf13%2Cf14%2Cf1%2Cf2%2Cf4%2Cf3%2Cf152%2Cf5%2Cf6%2Cf7%2Cf15%2Cf18%2Cf16%2Cf17%2Cf10%2Cf8%2Cf9%2Cf23&fid=f3&pn={i}&pz=20&po=1&dect=1&ut=fa5fd1943c7b386f172d6893dbfba10b&wbp2u=%7C0%7C0%7C0%7Cweb&_=1762236231801"
    for i in range(1, 274)
]


def fetch(url):
    res = requests.get(
        url,
        headers=get_header(
            "https://quote.eastmoney.com/center/gridlist.html",
        ),
    )
    print(url, res.json())
    # return url ,res.json()


with concurrent.futures.ThreadPoolExecutor(max_workers=4) as executor:
    for url in urls:
        executor.submit(fetch, url)

    # 第二种方法
    # futures = [executor.submit(fetch,url)for url in urls]
    # for future in concurrent.futures.as_completed(futures):
    #     print(future.result())
